﻿using System;
using System.Windows.Forms;
using CQRS.Events;
using CQRS.Sample.Domain.Commands;

namespace CQRS.Example.SampleApplication.Views
{
    public partial class RegisterEmergencyForm : BaseForm
    {
        private readonly IBus<Command> _commandBus;
        private Guid _planeId;

        public RegisterEmergencyForm(IBus<Command> commandBus)
        {
            InitializeComponent();
            _commandBus = commandBus;
        }
        
        internal void Init(Guid planeId)
        {
            _planeId = planeId;
        }

        private void buttonRegisterEmergency_Click(object sender, EventArgs e)
        {
            var registerPlaneEmergencyCommand = new RegisterPlaneEmergencyCommand
                (_planeId, textBoxFlightNumber.Text, textBoxAirportName.Text, textBoxCrewCommander.Text, dateTimePickerEmergency.Value,
                comboBoxWeatherConditions.Text);
            _commandBus.Publish(registerPlaneEmergencyCommand);
            _commandBus.Commit();
            Close();

        }
    }
}
